fix: handle missing dictionary batch for null-only columns in IPC reader - #9623
Merged
Conversation
Per the IPC specification, dictionary batches may be omitted when all values in a dictionary-encoded column are null. The C++ implementation (Arrow C++ 17+) relies on this and does not emit a dictionary batch in such cases, which caused the Rust IPC reader to fail with: "Cannot find a dictionary batch with dict id: ..." When a dictionary batch is missing, synthesize an empty values array of the appropriate type so decoding can proceed.
Contributor
|
Looks like this was added to the spec 7 years ago: |
alamb
approved these changes
Apr 6, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the contribution @joaquinhuigomez -- this looks good to me
I double checked that this matches the spec and that thsi was added to the spec 7 years ago in apache/arrow@0ddc1f4 / apache/arrow#5585
cc @pierrebelzile as the filer of
I also took the liberty of merging up from main and fixing clippy and fmt and simplifying the test a bit
| // Each message is: [continuation (4 bytes)] [meta_len (4 bytes)] | ||
| // [metadata (meta_len bytes)] [body (bodyLength bytes)] | ||
| let mut header = [0u8; 4]; | ||
| if std::io::Read::read_exact(&mut cursor, &mut header).is_err() { |
Contributor
There was a problem hiding this comment.
this is a strange way to write read_exact -- most other times I see it like
cursor.read_exact(&mut header).is_err() {
Contributor
There was a problem hiding this comment.
I took the liberty of pushing a commit to simplify it
Contributor
|
Thanks again @joaquinhuigomez |
Rich-T-kid
pushed a commit
to Rich-T-kid/arrow-rs
that referenced
this pull request
Jun 2, 2026
…der (apache#9623) # Which issue does this PR close? - Closes apache#9595 # Rationale for this change The [IPC specification](https://arrow.apache.org/docs/format/Columnar.html#format-ipc) states: > An edge-case for interleaved dictionary and record batches occurs when the record batches contain dictionary encoded arrays that are completely null. In this case, the dictionary for the encoded column might appear after the first record batch. Arrow C++ (v17+) relies on this and does not emit a dictionary batch when all values in a dictionary-encoded column are null. The Rust IPC reader currently fails with `"Cannot find a dictionary batch with dict id: ..."` when reading such streams, making cross-language interop broken for this edge case. # What changes are included in this PR? When the IPC reader encounters a `Dictionary`-typed column whose `dict_id` has no corresponding entry in `dictionaries_by_id`, it now synthesizes an empty values array of the appropriate type (via `new_empty_array`) instead of returning an error. This matches the spec's allowance for omitted dictionary batches on null-only columns. # Are these changes tested? Yes. A new test (`test_read_null_dict_without_dictionary_batch`) writes an IPC stream with an all-null dictionary column, strips the dictionary batch message from the raw bytes to simulate C++ behavior, then verifies the Rust reader successfully decodes the stream. # Are there any user-facing changes? IPC streams produced by C++ (or other implementations) that omit dictionary batches for null-only dictionary columns can now be read without error. Previously these streams caused a `ParseError`. --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
The IPC specification states:
Arrow C++ (v17+) relies on this and does not emit a dictionary batch when all values in a dictionary-encoded column are null. The Rust IPC reader currently fails with
"Cannot find a dictionary batch with dict id: ..."when reading such streams, making cross-language interop broken for this edge case.What changes are included in this PR?
When the IPC reader encounters a
Dictionary-typed column whosedict_idhas no corresponding entry indictionaries_by_id, it now synthesizes an empty values array of the appropriate type (vianew_empty_array) instead of returning an error. This matches the spec's allowance for omitted dictionary batches on null-only columns.Are these changes tested?
Yes. A new test (
test_read_null_dict_without_dictionary_batch) writes an IPC stream with an all-null dictionary column, strips the dictionary batch message from the raw bytes to simulate C++ behavior, then verifies the Rust reader successfully decodes the stream.Are there any user-facing changes?
IPC streams produced by C++ (or other implementations) that omit dictionary batches for null-only dictionary columns can now be read without error. Previously these streams caused a
ParseError.